with Ada.Calendar; use Ada.Calendar;
with Ada.Strings; use Ada.Strings;
with Ada.Strings.Unbounded;
with Ada.Finalization;
with Ada.Containers; use Ada.Containers;
with Ada.Containers.Doubly_Linked_Lists;
with Legend.Renders;
with Legend.Colors; 
package Legend.Controls is
   use Ada.Finalization;

   type Horizontal_Align is (ha_Left, ha_Center, ha_Right);
   type Vertical_Align is (va_Top, va_Center, va_Bottom);

   type Control_Type is new Limited_Controlled and Renders.Painter_Type with 
   record
      Canvas     : Renders.Canvas_Type(Control_Type'Unrestricted_Access);
      Visible    : Boolean := True;
      Size       : Point_Type;
      Position   : Point_Type := (0, 0);
      Back_Color : Color_Type := Colors.Black;
      Z_Index    : Integer := 0;
      Life       : Time := Clock;
      Managed    : Boolean := False;
   end record;

   overriding
   procedure Paint (this : in out Control_Type) is null;

   procedure Prepare (this : in out Control_Type) is null;

   subtype Control_Class is Control_Type'Class;

   type Control_Access is access all Control_Type'Class;

   package Control_Lists is
      new Doubly_Linked_Lists(Control_Access);

   procedure Delete is
      new Ada.Unchecked_Deallocation(Control_Class, Control_Access);

   function Compare_By_Z_Index (C1, C2 : Control_Access) return Boolean;

   package Control_Lists_Sortting is
      new Control_Lists.Generic_Sorting(Compare_By_Z_Index);

   procedure Paint_Controls (
      List   : in out Control_Lists.List;
      Target : in out Renders.Canvas_Type'Class
      );


   type Font_Type is record
      Name  : Unbounded.Unbounded_String;
      Size  : Uint16_t;
      Color : Color_Type;
   end record;

   type Label_Type is new Control_Type with private;

   function Text (this : Label_Type) return UTF8_String;

   procedure Text (this : in out Label_Type; Value : UTF8_String);

   procedure Autosize (this : in out Label_Type; Value : Boolean);

   function Font (this : in out Label_Type) return access Font_Type;

   procedure Font (this : in out Label_Type; Value : Font_Type);

   overriding
   procedure Paint (this : in out Label_Type);

   overriding
   procedure Initialize (this : in out Label_Type);


   type Label_Access is access Label_Type'Class;

   type Fog_Type is new Control_Type with private;

   overriding
   procedure Paint (this : in out Fog_Type);

   overriding
   procedure Initialize (this : in out Fog_Type);

   type Fog_Access is access all Fog_Type'Class;

private

   type Label_Type is new Control_Type with record
      F_Text     : Unbounded.Unbounded_String;
      F_Font     : aliased Font_Type;
      F_Autosize : Boolean;
   end record;

   type Fog_Type is new Control_Type with null record;



end Legend.Controls;
